/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import java.io.Serializable;
import java.util.List;
import java.util.Vector;
import javax.faces.bean.ManagedBean;
import javax.persistence.*;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.Transaction;
import util.HibernateUtil;


@ManagedBean(name = "parcours")
@Entity
@Table(name = "PARCOURS")
public class ParcoursBean implements Serializable {

    @Column(name = "INTITULE")
    private String intitule;
    @Id
    @Column(name = "id")
    private int id;
    //private Vector<String> requestedPlanningPath=new Vector<>(); 
    
    private List<ParcoursBean> listeParcours;
 
    public ParcoursBean getParcours(int id){
        Session session = HibernateUtil.getSession();
        List listeParcours=null;
        try {
            final Transaction transaction = session.beginTransaction();
            try {
                SQLQuery requete = session.createSQLQuery("SELECT INTITULE"
                        + " FROM PARCOURS WHERE ID="+id);
                listeParcours = requete.list();
                System.out.println("resultats: "+listeParcours.toString());
                // The real work is here
                transaction.commit();
            } catch (Exception ex) {
                // Log the exception here
                transaction.rollback();
                throw ex;
            }
        } finally {
            HibernateUtil.closeSession();
        }

        //tx.commit();
        return (ParcoursBean) listeParcours.get(0);
    }
    public List<ParcoursBean> getListeParcours() {
        Session session = HibernateUtil.getSession();
        List<ParcoursBean> listeParcours=null;
        try {
            final Transaction transaction = session.beginTransaction();
            try {
                SQLQuery requete = session.createSQLQuery("SELECT INTITULE"
                        + " FROM PARCOURS");
                listeParcours = requete.list();
                System.out.println("resultats: "+listeParcours.toString());
                // The real work is here
                transaction.commit();
            } catch (Exception ex) {
                // Log the exception here
                transaction.rollback();
                throw ex;
            }
        } finally {
            HibernateUtil.closeSession();
        }

        //tx.commit();
        this.listeParcours=listeParcours;
        return listeParcours;
    }
    public void setId(int id) {
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public void setIntitule(String intitule) {
        this.intitule = intitule;
    }

   

    /*public void setPlanningGlePath(String planningGlePath) {
     this.planningGlePath = planningGlePath;
     }

     public void setRequestedPlanningPath(String requestedPlanning) {
     if(!requestedPlanning.contains(requestedPlanning)){
     requestedPlanningPath.add(requestedPlanning);
     }
     }*/
    public String getIntitule() {
        return intitule;
    }
    /*
     public String getPlanningGlePath() {
     return planningGlePath;
     }
     */
    public boolean equals(Object obj) {
    if (obj == this) return true;
    if (!(obj instanceof ParcoursBean)) return false;

     

    return true;
}
}